setGlobalDuration(-1)

example = 1

if example == 1:
    # pitchs of instrument inside midiSynth are transposed on the base of centralkey
    beginMidiSynth(centralkey=60, release=2, pitchbend=2)
    freqMod(pitch=[100, 50], amplitude=.5, carrier=1, modulator=.498, pan=[0,1])
    pluckedString(amplitude=.5, cutoff=3000)
    endMidiSynth()


if example == 2:
    # You can define more than one midiSynth and assign them to different midi channels

    # channel 1
    beginMidiSynth(channel=1, centralkey=60, release=2, pitchbend=12)
    # midi controller inside midiSynth 
    midiSynthCtl(bus='ind', ctlnumber=74, minscale=0, maxscale=10)
    freqMod(pitch=[100, 50], amplitude=.5, carrier=1, modulator=.498, pan=[0,1], indexVar='ind')
    pluckedString(amplitude=.5, cutoff=3000)
    endMidiSynth()


    # channel 2
    beginMidiSynth(channel=2, centralkey=60, release=2, pitchbend=12)
    playSound('ounkmaster.aif')
    endMidiSynth()


if example == 3:
    beginMidiSynth(centralkey=60)
    playSound('ounkmaster.aif')
    endMidiSynth(out='synth') # route midiSynth to an audio bus
    convolveReverb(input='synth')


if example == 4:
    # assign audio and controller bus inside midiSynth
    beginMidiSynth(centralkey=60, release=3)
    playSound(sound='ounkmaster.aif', pitch=[1.001,.999], loop=True, pan=[0,1], amplitude=1, out='toRing1')
    linsegr(bus='rev', i1=0, dur1=.5, i2=.5, dur2=1, i3=0, final=1)
    sine(pitch=[500,1000], amplitude=1, out='toRing2')
    ringMod(in1='toRing1', in2='toRing2', out='toRev')
    waveguideReverb(input='toRev', mix=1, mixVar='rev')
    endMidiSynth()


startCsound()